<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  
  <title>1-环境搭建及海龟示例demo | ChenBlue | 飞雪连天射白鹿 笑书神侠倚碧鸳</title>

  
  <meta name="author" content="ChenBlue">
  

  
  <meta name="description" content="学习笔记">
  

  
  
  <meta name="keywords" content="ROS">
  

  <meta id="viewport" name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">

  <meta property="og:title" content="1-环境搭建及海龟示例demo"/>

  <meta property="og:site_name" content="ChenBlue"/>

  
  <meta property="og:image" content="/blog/favicon.ico"/>
  

  <link href="/blog/favicon.ico" rel="icon">
  <link rel="alternate" href="/blog/atom.xml" title="ChenBlue" type="application/atom+xml">
  <link rel="stylesheet" href="/blog/css/style.css" media="screen" type="text/css">
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
<div class="blog">
  <div class="content">

    <header>
  <div class="site-branding">
    <h1 class="site-title">
      <a href="/blog/">ChenBlue</a>
    </h1>
    <p class="site-description">飞雪连天射白鹿 笑书神侠倚碧鸳</p>
  </div>
  <nav class="site-navigation">
    <ul>
      
    </ul>
  </nav>
</header>

    <main class="site-main posts-loop">
    <article>

  
    
    <h3 class="article-title"><span>1-环境搭建及海龟示例demo</span></h3>
    
  

  <div class="article-top-meta">
    <span class="posted-on">
      <a href="/blog/2021/04/12/1-环境搭建及海龟示例demo/" rel="bookmark">
        <time class="entry-date published" datetime="2021-04-12T12:39:03.000Z">
          2021-04-12
        </time>
      </a>
    </span>
  </div>


  

  <div class="article-content">
    <div class="entry">
      
        <h1 id="安装-ROS-环境"><a href="#安装-ROS-环境" class="headerlink" title="安装 ROS 环境"></a>安装 ROS 环境</h1><p><em><strong>需要注意切换到国内的镜像源，进行安装</strong></em></p>
<h4 id="修改国内源"><a href="#修改国内源" class="headerlink" title="修改国内源"></a>修改国内源</h4><p><strong>1. 备份</strong></p>
<p> 备份/etc/apt/sources.list，命令如下：<br> <pre class="language-none"><code class="language-none">sudo cp &#x2F;etc&#x2F;apt&#x2F;sources.list &#x2F;etc&#x2F;apt&#x2F;sources.list.bak</code></pre><br><strong>2. 修改Ubuntu的源列表</strong></p>
<p>修改 <code>/etc/apt/sources.list</code> 文件下的列表，特别需要说明的是这些列表和当前的Ubuntu系统的版本有关，不同版本使用不同的配置。例如</p>
<p><strong>官方中国 Ubuntu 18.04 更新源</strong></p>
<pre class="language-none"><code class="language-none">deb http:&#x2F;&#x2F;cn.archive.ubuntu.com&#x2F;ubuntu&#x2F; bionic main restricted universe multiverse
deb http:&#x2F;&#x2F;cn.archive.ubuntu.com&#x2F;ubuntu&#x2F; bionic-security main restricted universe multiverse
deb http:&#x2F;&#x2F;cn.archive.ubuntu.com&#x2F;ubuntu&#x2F; bionic-updates main restricted universe multiverse
deb http:&#x2F;&#x2F;cn.archive.ubuntu.com&#x2F;ubuntu&#x2F; bionic-proposed main restricted universe multiverse
deb http:&#x2F;&#x2F;cn.archive.ubuntu.com&#x2F;ubuntu&#x2F; bionic-backports main restricted universe multiverse
deb-src http:&#x2F;&#x2F;cn.archive.ubuntu.com&#x2F;ubuntu&#x2F; bionic main restricted universe multiverse
deb-src http:&#x2F;&#x2F;cn.archive.ubuntu.com&#x2F;ubuntu&#x2F; bionic-security main restricted universe multiverse
deb-src http:&#x2F;&#x2F;cn.archive.ubuntu.com&#x2F;ubuntu&#x2F; bionic-updates main restricted universe multiverse
deb-src http:&#x2F;&#x2F;cn.archive.ubuntu.com&#x2F;ubuntu&#x2F; bionic-proposed main restricted universe multiverse
deb-src http:&#x2F;&#x2F;cn.archive.ubuntu.com&#x2F;ubuntu&#x2F; bionic-backports main restricted universe multiverse</code></pre>
<p><strong>3. 最后执行更新源命令</strong></p>
<pre class="language-none"><code class="language-none">sudo apt-get update
sudo apt-get upgrade</code></pre>
<h2 id="安装-ROS-melodic"><a href="#安装-ROS-melodic" class="headerlink" title="安装 ROS-melodic"></a>安装 ROS-melodic</h2><pre class="language-none"><code class="language-none">sudo sh -c &#39;echo &quot;deb http:&#x2F;&#x2F;packages.ros.org&#x2F;ros&#x2F;ubuntu $(lsb_release -sc) main&quot; &gt; &#x2F;etc&#x2F;apt&#x2F;sources.list.d&#x2F;ros-latest.list&#39;

sudo apt-key adv --keyserver &#39;hkp:&#x2F;&#x2F;keyserver.ubuntu.com:80&#39; --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

sudo apt update
sudo apt install ros-melodic-desktop-full rospack-tools

sudo rosdep init

rosdep update

echo &quot;source &#x2F;opt&#x2F;ros&#x2F;melodic&#x2F;setup.zsh&quot; &gt;&gt; ~&#x2F;.zshrc

source ~&#x2F;.zshrc

sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential</code></pre>
<h5 id="如果是Python3-需要安装一些依赖"><a href="#如果是Python3-需要安装一些依赖" class="headerlink" title="如果是Python3 需要安装一些依赖"></a>如果是Python3 需要安装一些依赖</h5><pre class="language-none"><code class="language-none">sudo apt-get install -y python3-pip
sudo pip3 install rospkg netifaces defusedxml</code></pre>

<p>安装完成后进行测试</p>
<p>终端中输入命令 <code>roscore</code></p>
<h4 id="小海龟示例"><a href="#小海龟示例" class="headerlink" title="小海龟示例"></a>小海龟示例</h4><p>第一个终端输入   <code>roscore</code></p>
<p>第二个终端输入 <code>rosrun turtlesim turtlesim_node</code></p>
<p><code>rostopic pub -r 10 xxxx/cmd_vel geometry_msgs/Twist (table)</code></p>
<p>第三个终端输入 <code>rosrun turtlesim turtle_teleop_key</code></p>
<h4 id="ROS-可视化工具"><a href="#ROS-可视化工具" class="headerlink" title="ROS 可视化工具"></a>ROS 可视化工具</h4><pre class="language-none"><code class="language-none">rqt_graph</code></pre>

      
    </div>

  </div>

  <div class="article-footer">
    <div class="article-meta pull-left">

    
      

    <span class="post-categories">
      <i class="icon-categories"></i>
        <a href="/blog/categories/ROS-学习笔记/">ROS 学习笔记</a>
    </span>
    

    
    

    <span class="post-tags">
      <i class="icon-tags"></i>
        <a href="/blog/tags/ROS/">ROS</a>
    </span>
    

    </div>

    
  </div>
</article>

  









    </main>

    <footer class="site-footer">
  <p class="site-info">
    Proudly powered by <a href="https://hexo.io/" target="_blank">Hexo</a> and
    Theme by <a href="https://github.com/CodeDaraW/Hacker" target="_blank">Hacker</a>
    </br>
    
    &copy; 2023 ChenBlue
    
  </p>
</footer>
    
    
  </div>
</div>
</body>
</html>